package admin

import (
	"github.com/mars/internal/admin/options"
	"github.com/mars/pkg/app"
	"github.com/mars/pkg/loggers"
)

const commandDesc = "通用的管理平台"

func NewApp(basename string) *app.App {
	opts := options.NewOptions()
	application := app.NewApp("Admin",
		basename,
		app.WithOptions(opts),
		app.WithDescription(commandDesc),
		app.WithDefaultValidArgs(),
		app.WithRunFunc(run(opts)),
		app.WithInitFunc(func() { loggers.Setup(opts.LogOption.NewLogConfig()) }),
	)

	return application
}

func run(opts *options.Options) app.RunFunc {
	return func(basename string) error {
		defer loggers.Sync()
		return Run(opts)
	}
}
